package com.ld.security.common.core.util;

import com.ld.security.common.core.base.column.ListString;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

    static Pattern p = Pattern.compile("\\s*|\t|\r|\n");

    /**
     * 删除换行符
     * @param str
     * @return
     */
    public static String removeLine(String str){
        Matcher m = p.matcher(str);
        String content = m.replaceAll("");
        return content;
    }

    public static boolean isNull(String s){
        if(s == null || s.length() == 0) {
            return true;
        }
        return false;
    }

    public static boolean match(String x,String y){

        ListString xs = new ListString(x);
        ListString ys = new ListString(y);
        boolean[] bs = new boolean[xs.size()];
        for(int i = 0;i<xs.size() && i<ys.size();i++){
            if(xs.get(i).equals("*")){
                bs[i]=true;
            }else if(xs.get(i).equals(ys.get(i))){
                bs[i]=true;
            }
        }
        boolean b=true;
        for (boolean b1 : bs) {
            b&=b1;
        }
        return b;
    }

}
